import { type FC } from 'react';
import { usePathname } from 'expo-router';
import RootRedirect from './redirect';
import { useAuth } from '@/hooks/useAuth';

const whiteList = [
  '/signup',
  '/profileSteps'
];

type RootAuthProps = {
  children?: (logined: boolean) => any;
}

const RootAuth: FC<RootAuthProps> = (props) => {
  const pathname = usePathname();
  const [logined, loading] = useAuth();

  if (loading) {
    return null;
  }

  // 白名单不受登录影响
  if (whiteList.includes(pathname)) {
    return null;
  }

  return (
    <RootRedirect
      path={pathname}
      logined={logined}
      children={props.children}
    />
  );
}

export default RootAuth;
